package com.hand.cloud.b2b.taobao;

import com.hand.cloud.b2b.enums.EPProductType;
import com.hand.cloud.b2b.model.EPProductModel;
import com.taobao.api.ApiException;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.ItemAddRequest;
import com.taobao.api.response.ItemAddResponse;


/**
 * 商品新增接口
 * 
 * @author linjinxiao
 * 
 */
public class AddItem
{
	final String appkey = "1021820838";
	final String secret = "sandbox2a3b4dbc7f7139ac4d7304bdf";
	final String sessionKey = "6100514c989b9e3202e9af1e58de9777de922c64deeceff3638380614";
	final String url = "http://gw.api.tbsandbox.com/router/rest";

	/**
	 * @param product
	 * @return
	 */
	public String createProduct(final EPProductModel product)
	{
		final TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret);
		final ItemAddRequest req = new ItemAddRequest();
		req.setNum(product.getNum());//数量
		req.setPrice(product.getPrice().toString());//价格
		req.setType(product.getType().toString());//一口价，非拍卖
		//req.setStuffStatus(product.getStuff_status().toString());//全新，非二手
		req.setStuffStatus(product.getStuffStatus().toString());
		req.setTitle(product.getTitle());
		req.setDesc(product.getDesc());
		//req.setLocationState(product.getLocation_state());
		req.setLocationState(product.getLocationState());
		//req.setLocationCity(product.getLocation_city());
		req.setLocationCity(product.getLocationCity());
		req.setCid(product.getCid());//电子凭证，商品子类目
		req.setOuterId("5432112345");//外部系统的主键
		try
		{
			final ItemAddResponse response = client.execute(req, sessionKey);

			System.out.println(response.getBody());
		}
		catch (final ApiException e)
		{
			e.printStackTrace();
		}
		return "";
	}

	public static void main(final String[] args)
	{

		final AddItem addItem = new AddItem();

		final EPProductModel product = new EPProductModel();

		product.setNum(333399L);//数量
		product.setPrice(18880d);//价格
		product.setType(EPProductType.FIXED);//一口价，非拍卖
		//product.setStuff_status(EPProductStuffStatus.NEW);//全新，非二手

		product.setTitle("沙箱测试_hybris服务");
		product.setDesc("最好的hybris");
		//product.setLocation_city("上海");
		product.setLocationCity("上海");
		//product.setLocation_state("上海");
		product.setLocationState("上海");
		product.setCid(50067207L);//电子凭证，商品子类目
		//product.setSource_pk("6827348249");//外部系统的主键
		//		product.setSourcePk("6827348249");
		product.setSourceProduct(null);

		addItem.createProduct(product);

	}
}
